Lamp = Widget.extend({
	ctor:function(){
		this._super();
		this.loadLamp();
		this.setTag(TAG_LAMP);
	},
	loadLamp : function(){
		this.setCascadeOpacityEnabled(true);
		var lamp = new Button(this, 7, TAG_JIUJINGDENG, "#jiujingdeng2.png",this.callback);
		lamp.setCascadeOpacityEnabled(true);
		var lid = new Button(this, 10, TAG_DENGMAO, "#dengmao.png",this.callback);
		lid.setPosition(0, 25);
		var huo = new Button(this, 10, TAG_HUOCHAI, "#huochai.png",this.callback);
		huo.setPosition(-200, 0);
		huo.setScale(0.1);
	},
	loadFire : /**
	 * 点火
	 */
		function(){
		var fire = new cc.Sprite("#fire2/1.png");
		fire.setPosition(27, 76);
//		fire.setScale(0.2);
		this.getChildByTag(TAG_JIUJINGDENG).addChild(fire, 7, TAG_LAMP_FIRE);

		var animFrames = [];
		for (var i = 1; i < 4; i++) {
			var str = "fire2/" + i + ".png";
			var frame = cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation = new cc.Animation(animFrames, 0.05);
		var action = cc.animate(animation);
		var repeat = cc.repeatForever(action);
		fire.runAction(repeat);
	},
	callback:function(p){
		var func = cc.callFunc(this.actionDone, this);
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_JIUJINGDENG:
			if(action==ACTION_DO1){
				var move=cc.moveTo(0.6,cc.p(-210,-21));
				var seq=cc.sequence(move,func);
				p.runAction(seq);
			}else if(action==ACTION_DO2){
				var tie=this.getParent().getChildByTag(TAG_TIEJIATAI2);			
				tie.removeFromParent();
				var move=cc.moveTo(0.6,cc.p(0,0));
				var seq=cc.sequence(move,func);
				p.runAction(seq);					
			}else if(action==ACTION_DO3){
				var move=cc.moveTo(0.6,cc.p(198,-15));
				var seq=cc.sequence(move,func);
				p.runAction(seq);
			}else if(action==ACTION_DO4){
				var move=cc.moveTo(0.6,cc.p(0,0));
				var seq=cc.sequence(move,func);
				p.runAction(seq);	
			}
			break;
		case TAG_DENGMAO:
			if(action==ACTION_DO1){
				var ber = cc.bezierBy(1,[cc.p(-20,60),cc.p(-30,20),cc.p(-70,-70)]);
				var seq=cc.sequence(ber,func);
				p.runAction(seq);
			}else if(action==ACTION_DO2){
				var ber = cc.bezierBy(1,[cc.p(20,110),cc.p(30,85),cc.p(70,75)]);
				var seq=cc.sequence(ber,cc.callFunc(function() {
					var fire=this.getChildByTag(TAG_JIUJINGDENG).getChildByTag(TAG_LAMP_FIRE);
					fire.setVisible(false);
				}, this),func);
				p.runAction(seq);
			}else if(action==ACTION_DO3){
				var ber = cc.bezierBy(2,[cc.p(-30,60),cc.p(-40,70),cc.p(0,0)]);
				var seq=cc.sequence(ber,func);
				p.runAction(seq);
			}else if(action==ACTION_DO4){
				var ber = cc.bezierBy(2,[cc.p(-30,60),cc.p(-40,70),cc.p(0,0)]);
				var seq=cc.sequence(ber,func);
				p.runAction(seq);
			}
			break;
		case TAG_HUOCHAI:
			var huo=new cc.Sprite("#huochai3.png");
			huo.setPosition(-200,-10);
			huo.setScale(0.25);
			this.addChild(huo,11);
			var move=cc.moveTo(1, cc.p(0,30));	
			var fad=cc.fadeOut(0);
			var seq=cc.sequence(move,fad,func);
			huo.runAction(seq);
			break;
		default:
			break;
		}
	},
	actionDone:function(p){
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_JIUJINGDENG:			
			gg.flow.next();				
			break;
		case TAG_DENGMAO:
			if(action==ACTION_DO1){
				gg.flow.next();
			}else if(action==ACTION_DO2){
				gg.flow.next();
			}else if(action==ACTION_DO3){				
				var seq=cc.sequence(cc.fadeOut(0),cc.callFunc(function() {
					gg.flow.next();
					this.getParent().clock.loadTip("#tool/tip3.png");
					this.getParent().clock.doTime(4, 0.2);						
				}, this),cc.delayTime(1.5),cc.callFunc(function(){
					var beaker=this.getParent().getChildByTag(TAG_BEAKER2);
					beaker.showJingti();						
				},this),cc.callFunc(function() {
					this.removeFromParent();
				},this));
				this.runAction(seq);
			}else if(action==ACTION_DO4){
				this.removeFromParent();
				gg.flow.next();
			}	
			break;
		case TAG_HUOCHAI:
			gg.flow.next();
			p.removeFromParent();
			break;
		case TAG_DEFAULT:
			var huo=this.getChildByTag(TAG_HUOCHAI);
			this.loadFire();
			huo.setVisible(false);
			gg.flow.next();
			break;
		}
	}
});
